package com.rtx.edi.platform.synctask.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rtx.api.annotation.RtxActivegatway;
import com.rtx.edi.model.api.bo.ApiMappingInfoBo;
import com.rtx.edi.model.qm.RtxQMResponse;
import com.rtx.edi.platform.synctask.service.GatWayService;
import com.rtx.wms.customer.k3.api.K3Api;

@RtxActivegatway("K3接口")
@Service("K3ApiGatWayService")
public class K3ApiCallBackServiceImpl  extends GatWayService{
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	K3Api k3Api;

	@Override
	protected String handleTarget(String targetjson, ApiMappingInfoBo bo) throws Exception {
		
		RtxQMResponse wmsRes = new RtxQMResponse();
		try {
			bo.getContent().setRequestContent(targetjson);
		    String	result = k3Api.getK3API().save(bo.getApimappingcode(), targetjson);
			com.alibaba.fastjson.JSONObject res = com.alibaba.fastjson.JSON.parseObject(result,com.alibaba.fastjson.JSONObject.class);
			String code = res.getJSONObject("Result").getJSONObject("ResponseStatus").getString("MsgCode");
			
			bo.getContent().setResponseContent(result);
			
			if(!"0".equals(code)) {
				wmsRes.setFailure(res.getJSONObject("Result").getJSONObject("ResponseStatus").getString("Errors"));
			}else {
				wmsRes.setSuccess("回传成功");
			}
		} catch (Exception e) {
			logger.error("请求异常-",e);
			wmsRes.setFailure(e.getMessage());
		}

		return com.alibaba.fastjson.JSON.toJSONString(wmsRes);
	}
	
	

}
